﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Creature.cs" company="melcoprog">
//   Copyright (c) melcoprog. All rights reserved.
// </copyright>
// <summary>
//   Defines the Creature type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Creature
{
    /// <summary>
    /// The creature.
    /// </summary>
    public abstract class Creature
    {
        /// <summary>
        /// The state machine.
        /// </summary>
        private readonly IStateMachine stateMachine;

        /// <summary>
        /// The state.
        /// </summary>
        private ICreatureState state;

        /// <summary>
        /// Initializes a new instance of the <see cref="Creature"/> class.
        /// </summary>
        /// <param name="stateMachine">
        /// The state machine.
        /// </param>
        /// <param name="state">
        /// The state.
        /// </param>
        protected Creature(IStateMachine stateMachine, ICreatureState state)
        {
            this.stateMachine = stateMachine;
            this.SetState(state);
        }

        /// <summary>
        /// Gets or sets the x.
        /// </summary>
        public double X { get; set; }

        /// <summary>
        /// Gets or sets the y.
        /// </summary>
        public double Y { get; set; }

        /// <summary>
        /// Gets or sets the velocity x.
        /// </summary>
        public double VelocityX { get; set; }

        /// <summary>
        /// Gets or sets the velocity y.
        /// </summary>
        public double VelocityY { get; set; }

        /// <summary>
        /// Gets or sets the acceleration x.
        /// </summary>
        public double AccelerationX { get; set; }

        /// <summary>
        /// Gets or sets the acceleration y.
        /// </summary>
        public double AccelerationY { get; set; }

        /// <summary>
        /// Gets or sets the speed.
        /// </summary>
        public double Speed { get; set; }

        /// <summary>
        /// Gets or sets the direction.
        /// </summary>
        public Direction Direction { get; set; }

        /// <summary>
        /// The set state.
        /// </summary>
        public void SetState()
        {
            this.state = this.stateMachine.GetNextState(this);
        }

        /// <summary>
        /// The make step.
        /// </summary>
        /// <returns>
        /// The <see cref="CreatureStep"/>.
        /// </returns>
        public CreatureStep MakeStep()
        {
            return this.state.MakeStep(this);
        }

        /// <summary>
        /// The set state.
        /// </summary>
        /// <param name="creatureState">
        /// The creature State.
        /// </param>
        protected void SetState(ICreatureState creatureState)
        {
            this.state = creatureState;
        }
    }
}
